local M = require "packages/mamashengde/record/Made"

local moqi = fk.CreateSkill {
  name = "shine__moqi",
}

Fk:loadTranslationTable {
  ["shine__moqi"] = "魔契",
  [":shine__moqi"] = "每次变身限一次，出牌阶段，你可以消耗至少3点魔力并失去所有体力，然后你令“恒辉”的所有数值翻倍。若如此做，你保持变身状态直到结束阶段。",

  ["lose_maryoku"] = "消耗1点魔力",
  ["#shine__moqi"] = "魔契：消耗至少3点魔力并失去所有体力，令“恒辉”数值翻倍且变身状态持续到结束阶段",
}

moqi:addEffect("active", {
  anim_type = "offensive",
  card_num = 0,
  target_num = 0,
  interaction = function(self, player)
    return UI.Spin {
      from = 3,
      to = M.getMaryoku(player),
    }
  end,
  prompt = "#shine__moqi",
  can_use = function(self, player)
    return player:usedSkillTimes(moqi.name, Player.HistoryGame) == 0 and M.getMaryoku(player) > 2 and
      table.find(player:getCardIds("h"), function(id)
        return not player:prohibitDiscard(id)
      end)
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = effect.from
    room:setPlayerMark(player,"moqi__keepHenshin", 1)
    local n = self.interaction.data
    M.changeMaryoku(player, -n, moqi.name)
    room:loseHp(player, player.hp, moqi.name)
    local a, b = player:getMark("@shine__henghui1"), player:getMark("@shine__henghui2")
    if a > 0 then
      room:addPlayerMark(player, "@shine__henghui1", a)
    elseif b > 0 then
      room:addPlayerMark(player, "@shine__henghui2", b)
    end
  end,
})

moqi:addEffect(M.HenshinExiting, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return data and data.who == player and player:getMark("moqi__keepHenshin") > 0
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    data.prevented = true
    return true
  end,
})

moqi:addEffect(fk.EventPhaseStart, {
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player.phase == Player.Finish and player:getMark("moqi__keepHenshin") > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player,"moqi__keepHenshin", 0)
    if M.exitHenshin(player, moqi.name) then
      -- 变身成功后的处理
      room:notifySkillInvoked(player, moqi.name, "positive")
    end
  end,
})

return moqi